home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / sysext / init / boottim.sit / BootTime ƒ / BootTime Source ƒ / BootTime.c < prev   
Encoding:
C/C++ Source or Header  |  1991-01-14  |  3.1 KB  |  172 lines

  1.  
  2. /*     BootTime INIT
  3.     ⌐ Mike Gleason Jr.
  4.     version 4.0  January 14, 1991.     */
  5.     
  6. #include "setupA4.h"
  7.     
  8.  
  9. /* constants to test GetKeys() with */
  10. #define d_key 5
  11. #define option_key 61
  12. #define spacebar_key 54
  13.  
  14.  
  15.  
  16. #pragma mark _prototypes
  17. void    main(void);
  18. void    DoIt(void);
  19.  
  20. struct 
  21. {
  22.     char privates[76];
  23.     long randSeed;
  24.     BitMap screenBits;
  25.     Cursor arrow;
  26.     Pattern dkGray;
  27.     Pattern ltGray;
  28.     Pattern gray;
  29.     Pattern black;
  30.     Pattern white;
  31.     GrafPtr thePort;
  32. }  *qdPtr;                  /* Size of QD Globals is 206 bytes. */
  33.  
  34.  
  35.  
  36. void    main(void)
  37. {    
  38.     KeyMap k;
  39.     Handle h;
  40.         
  41.     RememberA0();    
  42.     SetUpA4();
  43.  
  44.     /*    this and all the asm{} is by David Allcott of Symantec.
  45.         Thanks David! */        
  46.     asm
  47.     {                            ;guarantee that INIT is locked even
  48.         _RecoverHandle            ;if locked bit was not set with ResEdit
  49.         move.l    a0,h            ;save away handle to unlock later
  50.         _HLock                    ;handle is already in a0
  51.  
  52.         clr.l    0x0a6c            ;location of DeskHook low mem global
  53.                                 ;DeskHook is not cleared at init time on
  54.                                 ;all machines. it is cleared by 
  55.                                 ;Multifinder after inits run.
  56.                                 ;If you display a window and move
  57.                                 ;or dispose of it, the OS attempts to
  58.                                 ;redraw the desktop behind it, and calls
  59.                                 ;the deskhook (or attempts to call it)
  60.                                 ;if the low mem global is non-zero.
  61.                                 
  62.         clr.l    0x09f6            ;location of DragHook
  63.                                 ;same scenario as DeskHook (MJG)
  64.                                 
  65.         link a5,#(-300);        ;space for the Quickdraw globals
  66.         move.l    a5, CurrentA5    ;we now have our own A5 world
  67.         pea    -4(a5)
  68.         _InitGraf
  69.     }
  70.     InitFonts();
  71.     InitWindows();
  72.     InitDialogs(0L);
  73.     InitPack(bdConv);
  74.  
  75.     GetKeys(&k);
  76.     if (!(Button() || BitTst(&k, option_key) || BitTst(&k, spacebar_key)))
  77.         DoIt();
  78.     /* if you hold the option key or spacebar down, I won't load. */
  79.         
  80.     asm
  81.     {
  82.         unlk a5;
  83.         move.l    a5, CurrentA5;    /*    Restore the previous A5.            */
  84.     }
  85.     HUnlock(h);
  86.     DisposHandle(h);
  87.     RestoreA4();
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. void    DoIt(void)
  95. {
  96.     Rect                r;
  97.     register Str255        a = "\p", b;
  98.     register long        tyme, min, secs;
  99.     long                tix;
  100. #define DELAYTIX    90
  101.     
  102.         
  103.     /*  get the time elapsed since the machine was turned on, 
  104.         in minutes:seconds.fractionOfSecond form.  */
  105.             
  106.     tyme = TickCount();
  107.     tix = ((tyme - ((tyme / 60) * 60)) * 100) / 60;
  108.     min = tyme / 3600;
  109.     secs = (tyme - (min * 3600)) / 60;
  110.  
  111.     if (min)
  112.     {
  113.         NumToString(min, a);
  114.         
  115.         (*a)++; *(a + *a) = ' ';
  116.         (*a)++; *(a + *a) = 'm';
  117.         (*a)++; *(a + *a) = 'i';
  118.         (*a)++; *(a + *a) = 'n';
  119.         (*a)++; *(a + *a) = ' ';
  120.     }
  121.     
  122.     NumToString(secs, b);
  123.     (*a)++; *(a + *a) = *(b+1);
  124.     if (secs > 9)
  125.     {
  126.         (*a)++; *(a + *a) = *(b+2);    
  127.     }
  128.     
  129.     (*a)++; *(a + *a) = '.';
  130.     NumToString(tix, b);
  131.     if (tix < 10)
  132.     {
  133.         (*a)++; *(a + *a) = '0';    
  134.         (*a)++; *(a + *a) = *(b+1);    
  135.     }
  136.     else
  137.     {
  138.         (*a)++; *(a + *a) = *(b+1);    
  139.         (*a)++; *(a + *a) = *(b+2);    
  140.     }
  141.  
  142.     (*a)++; *(a + *a) = ' ';
  143.     (*a)++; *(a + *a) = 's';
  144.     (*a)++; *(a + *a) = 'e';
  145.     (*a)++; *(a + *a) = 'c';
  146.     
  147.     TextFont(0);
  148.     TextSize(12);
  149.     
  150.     SetRect(&r, 
  151.         10,
  152.         30,
  153.         10 + StringWidth(a) + 18,
  154.         56
  155.     );
  156.     
  157.     EraseRect(&r);
  158.     FrameRect(&r);
  159.     InsetRect(&r, 2, 2);
  160.     FrameRect(&r);
  161.     
  162.     MoveTo(r.left + 7, r.top + 16);
  163.     DrawString(a);
  164.     
  165.     tix = TickCount() + DELAYTIX;
  166.     do
  167.     {
  168.         if (Button()) break;
  169.     }
  170.     while (TickCount() < tix);    
  171. }
  172.